<template>
  <div style="position: relative">
    <div class="content">
      <div class="info" v-if="this.$route.query.type == 1 ? true : false">
        <div class="title">基本信息</div>
        <div class="list">
          <div class="item">
            <div class="tit">商户订单号</div>
            <div class="desc">
              {{ detailList.payformNo ? detailList.payformNo : "-" }}
            </div>
            <div
              v-if="detailList.payformNo"
              style="
                margin-left: 32px;
                color: #03bfc6;
                line-height: 40px;
                cursor: pointer;
              "
            >
              <i
                class="el-icon-document-copy"
                @click="copyAppId(detailList.payformNo)"
              ></i>
            </div>
          </div>
          <div class="item">
            <div class="tit">云尘付流水号</div>
            <div class="desc">
              {{ detailList.innerPayformNo ? detailList.innerPayformNo : "-" }}
            </div>
            <div
              v-if="detailList.innerPayformNo"
              style="
                margin-left: 32px;
                color: #03bfc6;
                line-height: 40px;
                cursor: pointer;
              "
            >
              <i
                class="el-icon-document-copy"
                @click="copyAppId(detailList.innerPayformNo)"
              ></i>
            </div>
          </div>
          <div class="item">
            <div class="tit">商品名称</div>
            <div class="desc">
              {{ detailList.subject ? detailList.subject : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">支付金额/元</div>
            <div class="desc">
              {{ detailList.fmtActualAmount ? detailList.fmtActualAmount : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">支付渠道</div>
            <div class="desc">
              {{ detailList.channelTagName ? detailList.channelTagName : "-" }}
            </div>
          </div>
        </div>
      </div>
      <div class="info" v-if="this.$route.query.type == 1 ? true : false">
        <div class="title">审核信息</div>
        <div class="list">
          <div class="item">
            <div class="tit">退款申请时间</div>
            <div class="desc">
              {{ detailList.gmtCreated ? detailList.gmtCreated : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">退款金额/元</div>
            <div class="desc">
              {{ detailList.fmtRefundAmt ? detailList.fmtRefundAmt : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">退款发起人</div>
            <div class="desc">
              {{ detailList.createUserName ? detailList.createUserName : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">退款理由</div>
            <div class="desc">
              {{ detailList.refundRemark ? detailList.refundRemark : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核状态</div>
            <div class="desc">
              {{
                detailList.auditStatus
                  ? setAuditStatus(detailList.auditStatus)
                  : "-"
              }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核时间</div>
            <div class="desc">
              {{ detailList.auditTime ? detailList.auditTime : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核人</div>
            <div class="desc">
              {{ detailList.auditUserName ? detailList.auditUserName : "-" }}
            </div>
          </div>
        </div>
      </div>
      <div class="info" v-if="this.$route.query.type == 2 ? true : false">
        <div class="title">基本信息</div>
        <div class="list">
          <div class="item">
            <div class="tit">退款批次号</div>
            <div class="desc">
              {{ detailList.batchId ? detailList.batchId : "-" }}
            </div>
            <div
              v-if="detailList.batchId"
              style="
                margin-left: 32px;
                color: #03bfc6;
                line-height: 40px;
                cursor: pointer;
              "
            >
              <i
                class="el-icon-document-copy"
                @click="copyAppId(detailList.batchId)"
              ></i>
            </div>
          </div>
          <div class="item">
            <div class="tit">总笔数</div>
            <div class="desc">
              {{ detailsList.length }}
              <!-- {{ detailList.orderNum ? detailList.orderNum : "-" }} -->
            </div>
          </div>
        </div>
      </div>
      <div class="info" v-if="this.$route.query.type == 2 ? true : false">
        <div class="title">审核信息</div>
        <div class="list">
          <div class="item">
            <div class="tit">退款申请时间</div>
            <div class="desc">
              {{ detailList.gmtCreated ? detailList.gmtCreated : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">退款总金额/元</div>
            <div class="desc">
              {{ caculateAmount(detailsList) }}
              <!-- {{ detailList.fmtRefundAmt ? detailList.fmtRefundAmt : "-" }} -->
            </div>
          </div>
          <div class="item">
            <div class="tit">退款发起人</div>
            <div class="desc">
              {{ detailList.createUserName ? detailList.createUserName : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">退款理由</div>
            <div class="desc">
              {{ detailList.refundRemark ? detailList.refundRemark : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核状态</div>
            <div class="desc">
              {{
                detailList.auditStatus
                  ? setAuditStatus(detailList.auditStatus)
                  : "-"
              }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核时间</div>
            <div class="desc">
              {{ detailList.auditTime ? detailList.auditTime : "-" }}
            </div>
          </div>
          <div class="item">
            <div class="tit">审核人</div>
            <div class="desc">
              {{ detailList.auditUserName ? detailList.auditUserName : "-" }}
            </div>
          </div>
        </div>
      </div>
      <div
        class="info"
        style="min-width: 1125px"
        v-if="this.$route.query.type == 2 ? true : false"
      >
        <div class="title">订单信息</div>
        <div style="margin-top: 45px">
          <tr class="openBox">
            <td>商户订单号</td>
            <td>云尘付流水号</td>
            <td>商品名称</td>
            <td>支付金额/元</td>
            <td>支付渠道</td>
            <td>退款状态</td>
          </tr>
          <div
            class="openBox1"
            v-for="(o, oIndex) in detailsList"
            :key="oIndex"
          >
            <td :title="o.payformNo">
              {{ o.payformNo ? o.payformNo : "-" }}
            </td>
            <td>
              {{ o.innerPayformNo ? o.innerPayformNo : "-" }}
            </td>
            <td>
              {{ o.subject ? o.subject : "-" }}
            </td>
            <td>
              {{ o.fmtActualAmount ? o.fmtActualAmount : "-" }}
            </td>
            <td>
              {{ o.payTypeName ? o.payTypeName : "-" }}
            </td>
            <td>
              {{ o.refundStatusName ? o.refundStatusName : "-" }}
            </td>
          </div>
        </div>
      </div>
    </div>
    <div class="back" @click="backFn">
      <i class="el-icon-close"></i>
    </div>
    <div class="left">
      <el-breadcrumb separator=">" style="margin-bottom: 20px">
        <el-breadcrumb-item v-for="item of breadList" :key="item">{{
          item
        }}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
  </div>
</template>
<script>
export default {
  name: "refundDetail",
  components: {},
  data() {
    return {
      detailsList: [],
      detailList: {},
      openShow: false,
      breadList: [],
    };
  },
  created() {
    this.breadList = this.$route.meta.title;
    let id = this.$route.query.id;
    if (id) {
      this.$http.get(`/api/merchant/refundAudit/get?id=${id}`).then((res) => {
        if (res.code === "0000") {
          this.detailList = res.data;
          if (this.$route.query.type == "2") {
            this.$http
              .get(
                `/api/merchant/refundAudit/listOrderByBatchId?batchId=${res.data.batchId}`
              )
              .then((res) => {
                if (res.code === "0000") {
                  this.detailsList = res.data;
                }
              });
          }
        }
      });
    }
  },
  methods: {
    caculateAmount(list) {
      let num = 0;
      list.length &&
        list.forEach((item) => {
         num += parseFloat(item.fmtRefundAmount);
        });
      return num.toFixed(2);
    },
    setAuditStatus(val) {
      let str = "";
      switch (val) {
        case "success_approval":
          str = "审核通过";
          break;
        case "wait_approval":
          str = "待审核";
          break;
        case "fail_approval":
          str = "审核拒绝";
          break;
      }
      return str;
    },
    backFn() {
      this.$backTo(`/deal/refund`);
    },
    copyAppId(value) {
      const input = document.createElement("input"); // 创建input对象
      input.value = value; // 设置复制内容
      document.body.appendChild(input); // 添加临时实例
      input.select(); // 选择实例内容
      document.execCommand("Copy"); // 执行复制
      document.body.removeChild(input); // 删除临时实例
      this.$message.success("复制成功！");
    },
  },
};
</script>
<style scoped lang="scss">
.content {
  min-height: 780px;
  padding: 160px 100px;
  display: flex;
  justify-content: start;
  flex-wrap: wrap;
  .info {
    width: 33.3%;
    min-width: 500px;
    margin-bottom: 40px;
    padding: 0 2%;
    .title {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #1d1c1c;
      padding-bottom: 15px;
      border-bottom: 1px solid #03bfc6;
    }
    .list {
      margin-top: 35px;
      .item {
        display: flex;
        .tit {
          min-width: 100px;
          margin-right: 32px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #869daa;
          line-height: 40px;
          text-align: right;
        }
        .desc {
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #1d1c1c;
          line-height: 40px;
          overflow: hidden;
          word-wrap: break-word;
        }
      }
    }
    .openBox {
      margin-bottom: 20px;
      height: 22px;
      font-size: 15px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #1d1c1c;
      line-height: 22px;
      display: flex;
      justify-content: start;
      td {
        display: inline-block;
        min-width: 14%;
        padding: 0 40px 0 0;
      }
    }
    .openBox1 {
      margin-bottom: 20px;
      height: 22px;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 400;
      color: #1d1c1c;
      line-height: 22px;
      display: flex;
      justify-content: start;
      text-align: left;
      td {
        padding: 0 40px 0 0;
        min-width: 14%;
        width: 1px;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}
.back {
  position: absolute;
  right: 55px;
  top: 20px;
  font-size: 20px;
  cursor: pointer;
}
.left {
  position: absolute;
  left: 55px;
  top: 31px;
  height: 20px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #869daa;
  line-height: 20px;
}
// :deep(.el-table__expand-icon) {
//   // position: absolute;
//   // left:140px;
//   float: left;
// }
@media screen and (max-width: 1770px) {
  .content {
    .info {
      box-sizing: content-box !important;
      width: 33.3%;
      min-width: 520px;
      margin-bottom: 40px;
      padding: 0 5.5%;
    }
  }
}

@media screen and (max-width: 1550px) {
  .content {
    .info {
      box-sizing: content-box !important;
      width: 33.3%;
      min-width: 488px;
      margin-bottom: 40px;
      padding: 0 2%;
    }
  }
}
</style>
